//
//  MOAreaModel.m
//  MOPickerView
//
//  Created by 莫业金 on 16/5/20.
//  Copyright © 2016年 moruiwei. All rights reserved.
//

#import "MOAreaModel.h"


@interface MOAreaModel()


@end


@implementation MOAreaModel
static MOAreaModel *model_area = nil;
//单例
+ (MOAreaModel *)shared
{
    if (model_area == nil) {
        model_area = [[MOAreaModel alloc] init];
    }
    return model_area;
}
- (NSMutableArray *)arry_allArea
{
    
    
    if (!_arry_allArea) {
        _arry_allArea = [NSMutableArray arrayWithArray:@[self.arry_provinceName,self.arry_cityName,self.arry_districtName]];
    }
    return _arry_allArea;
}
- (NSMutableArray *)arry_provinceName
{
    if (_arry_provinceName == nil) {
        
        _arry_provinceName = [NSMutableArray array];
        
        NSString *path = [[NSBundle mainBundle] pathForResource:@"area" ofType:@"json"];
        
        NSData *jsonData = [NSData dataWithContentsOfFile:path options:NSDataReadingMappedIfSafe error:nil];
        
        NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
        
        for (NSString *str_dics in [dic allKeys]) {
            [_arry_provinceName addObject:dic[str_dics][@"shortName"]];
        }
    }
    return _arry_provinceName;
}
- (NSMutableArray *)arry_cityName
{
    if (_arry_cityName == nil) {
        
        _arry_cityName = [NSMutableArray array];
        
        NSString *path = [[NSBundle mainBundle] pathForResource:@"area" ofType:@"json"];
        
        NSData *jsonData = [NSData dataWithContentsOfFile:path options:NSDataReadingMappedIfSafe error:nil];
        
        NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
        
        for (NSString *str_dics in [dic allKeys]) {
            NSMutableArray *arr_city = [NSMutableArray array];
            for (NSDictionary *dic_city in dic[str_dics][@"children"]) {
                [arr_city addObject:dic_city[@"shortName"]];
            }
            [_arry_cityName addObject:arr_city];
        }
    }
    return _arry_cityName;
}
- (NSMutableArray *)arry_districtName
{
    if (_arry_districtName == nil) {
        
        _arry_districtName = [NSMutableArray array];
        
        NSString *path = [[NSBundle mainBundle] pathForResource:@"area" ofType:@"json"];
        
        NSData *jsonData = [NSData dataWithContentsOfFile:path options:NSDataReadingMappedIfSafe error:nil];
        
        NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
        
        for (NSString *str_dics in [dic allKeys]) {
            
            NSMutableArray *arr_city = [NSMutableArray array];
            
            for (NSDictionary *dic_city in dic[str_dics][@"children"]) {
                
                NSMutableArray *arr_district = [NSMutableArray array];
                for (NSDictionary *dic_province in dic_city[@"children"]) {
                    [arr_district addObject:dic_province[@"shortName"]];
                }
                [arr_city addObject:arr_district];
                
            }
            [_arry_districtName addObject:arr_city];
        }
    }
    return _arry_districtName;
}



//- (NSArray *)array_single{
//    if (!_array_single) {
//        _array_single = [NSArray array];
//    }
//    return _array_single;
//}
/**
 *  自定义单行
 */
- (NSArray *)array_asingle{
    if (!_array_asingle) {
        
        _array_asingle = [NSMutableArray arrayWithArray:@[self.array_single]];
    }
    return _array_asingle;
}

@end
